<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<head>
<title>审核规则</title>
    <%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/import.jsp" %>
	<script type="text/javascript" src="${ctx}/js/util.js"></script>
	
	<script type="text/javascript">

	
	//提交数据数组
	var submitArray = [];
	var userDataFlag = false ;
	var roleDataFlag = false ;
	var userData =null;
	var roleData = null;
	var sysEname="${sysEname}";
	var fileName="${uploadFileName}";
	var deployId="${deployId}";
	
	var to_eidt_url = '${ctx}/audit/auditRule/toEdit.action';
	var flag = "${param.flag}";
	var ruleId = "${param.ruleId}";
	var edit_url = '${ctx}/audit/auditRule/editActOrUser.action?flag='+flag;
	
	
	$(function(){
		$.getJSON("${ctx}/uct/user/user!data.action?userEname=admin",function(data){
			userData=data;
			//初始化User
			initUser();
			
			if(ruleId!=null && ruleId!=""){
				$.ajax({
					url: to_eidt_url,
		  			method: "GET",
		  			async:false,
		  			data: { ruleId : '${param.ruleId}' },
		  			dataType: "json",
		  			success:function(data){
		  				var auditRule = data.auditRule;
		  				
						 FormUtil.fillData("#editAuditRuleForm", auditRule);
		  				 $("input:radio[name='ifStart'][value='"+auditRule.ifStart+"']").attr("checked", 'true');
		  				 //alert(auditRule.checkUser);['admin','atta']
		  				 var checkUser = auditRule.checkUser;
		  				 if(checkUser!=null && checkUser!=""){
		  					$('#user').combogrid('setValues',auditRule.checkUser.split(","));
		  				 }
		  				

	<%--	  				$("#ruleId").val(auditRule.ruleId);--%>
	<%--	  				$("#tableName").val(auditRule.tableName);--%>
	<%--	  				$("#checkUser").val(auditRule.checkUser);--%>
	<%--	  				$("#next").val(auditRule.next);--%>
	<%--	  				$("#last").val(auditRule.last);--%>
	<%--	  				$("#num").val(auditRule.num);--%>
	<%--	  				$("#auditType").val(auditRule.auditType);--%>
		  			}
				});
			}
		});
<%--		$.getJSON("${ctx}/uct/role/role!data.action",function(data){--%>
<%--			roleData=data;--%>
<%--			//初始化角色--%>
<%--			initRole();--%>
<%--		});--%>
		

		
		
		
		
		
		
		
	});
	
	
	
	function initUser(){
		$('#user').combogrid({
			panelWidth:240,
			multiple:true,
			idField:'userEname',
			textField:'userCname',
			onChange:function setXXX(){
				$("#checkUser").val($("#user").combogrid('getValues'));
			},
			columns:[[
				{field:'userEname',title:'账号',width:110},
				{field:'userCname',title:'姓名',width:110}
			]]
		});
		queryUser();
	}
	
	
	function queryUser(){
		$('#userspan').show();
		$('#rolespan').hide();
		$("input[name=type][value=user]").attr("checked",true);
		if(!userDataFlag){
			$($('#user').combogrid('grid')).datagrid('loadData',userData);
		}
		userDataFlag = true;
		$("input[name='crossDept']").attr("disabled",true); 
	}
	
	
	function initRole(){
		$('#role').combogrid({
			panelWidth:240,
			multiple:true,
			idField:'roleEname',
			textField:'roleCname',
<%--			onChange:function setXXX(){--%>
<%--				$("#checkUser").val($("#role").combogrid('getValues'));--%>
<%--			},--%>
			columns:[[
				{field:'roleEname',title:'账号',width:110},
				{field:'roleCname',title:'姓名',width:110}
			]]
		});
		queryRole();
	}
	
	function queryRole(){
		$('#rolespan').show();
		$('#userspan').hide();
		$("input[name=type][value=role]").attr("checked",true);
		if(!roleDataFlag){
			$($('#role').combogrid('grid')).datagrid('loadData',roleData);
		}
		roleDataFlag = true;
		$("input[name='crossDept']").attr("disabled",true); 
	}
	
	
	

	function save(){
		userValue = $("#user").combogrid('getValues');
		roleValue = $("#role").combogrid('getValues');
		typeValue = $(":radio[name='type']:checked").val();
		if(typeValue=="user"){
			if(userValue==""){
				$.messager.alert("必填校验警告","请选择用户！！！",'warning');
				return false;
			}
		}
		if(typeValue=="role"){
			if(roleValue==""){
				$.messager.alert("必填校验警告","请选择权限！！！",'warning');
				return false;
			}
		}
		$("#userValue").val(userValue);
		$("#roleValue").val(roleValue);
		$("#typeValue").val(typeValue);
		$('#editAuditRuleForm').form('submit', {
			type:'post',
		    url:edit_url,
		    data:$('#editAuditRuleForm').serialize(),
		    success:function(data){
		    	var oTxt = jQuery.parseJSON(data);
				var mess = oTxt.msg;
				var flag = oTxt.flag;
				if(flag=="T"){
					alert("操作成功");
					window.parent.closeWin();
					window.parent.reload();
		        	
				}else{
					alert("操作失败");
				}
				
		    },
		    error:function(){
				 alert("请检查服务器！");
			}
		});
     }

	
	function cancel(){
		window.parent.closeWin();
	}
	
	

	
	function showRoleUser(){
		var roleValue = $("[name='role']").val();
		var type= $("input[name=type]:checked").val();
		if(type == "role"){
			if(null != roleValue){
				var user_list_url = "${ctx}/uct/admin/user!list.action?roleEname=" + roleValue;
				$.ajax({ 
					type:'post',
					url:user_list_url,
					dataType:'json',
					async: false,
					success:function(data){
						$("#checkUser").val(data);
						$("#roleValue").val(data);
					}
				}); 
			}
		}
	}

	function setCheckUser(){
		var val = $('#user').combogrid('getValue');
		alert(val);
	}

	</script>
</head>
<body>	

		<form id="editAuditRuleForm" name="editAuditRuleForm" method="post" >
		
		<input type="hidden" name="userValue" id="userValue" value="${auditRule.userValue}"/>
		<input type="hidden" name="roleValue" id="roleValue" value=""/>
		<input type="hidden" name="typeValue" id="typeValue" value=""/>
			<%--<input type="hidden" name="formToken" id="formToken" value="${formToken}"/>
			--%><table class="datagrid-body">
			<tr>
				<td class="datagrid-header">规则ID<font color=red>*</font></td>
				<td>
					<input id="ruleId" name="ruleId" value="${param.ruleId}" style="background-color: #dddddd" type="text"  />
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">表名</td>
				<td>
					<input id="tableName"  name="tableName" value="${auditRule.tableName }" type="text" />
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">是否起点<font color=red>*</font></td>
				<td>
					<label><input type="radio" name="ifStart" value="T" >是</label>
					 
  					<label><input type="radio" name="ifStart" value="F" <c:if test="${param.ruleId ==null}"> checked="checked"</c:if>>否</label>
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">
					权限类型
				</td>
				<td>
					<label><input name="type" type="radio" value="role" onclick="queryRole()">权限</label>
					<label><input name="type" type="radio" value="user" onclick="queryUser()" checked="checked">用户</label>
				&nbsp;&nbsp;
					<span id="userspan" style="display: inline;">
						<input id="user" name="user" class="easyui-combogrid"  style="width: 200px;"></input>
					</span>
					<span id="rolespan" style="display: none;">
						<input id="role" name="role" class="easyui-combogrid"  style="width: 200px;"></input>
					</span>
					
<%--					<span id="rolespan" style="display:none;">--%>
<%--						<select id="role" name="role" class="easyui-combotree"  style="width:200px;"></select>--%>
<%--					</span>--%>
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">
					审核人<font color=red>*</font>
				</td> 
				<td>
					<input type="text" style="width:400px;" id ="checkUser" name="checkUser"  value="${auditRule.checkUser}" readonly="readonly"/>
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">通过</td>
				<td>
					<input type="text" id="next" name="next" value="${auditRule.next }" >
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">不通过</td>
				<td>
					<input type="text" id="last" name="last" value="${auditRule.last }" >
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">次数</td>
				<td>
					<input type="text" id="num" name="num" value="${auditRule.num }" >
				</td>
			</tr>
			<tr>
				<td class="datagrid-header">审核类型</td>
				<td>
					<input type="text" id="auditType" name="auditType" value="${auditRule.auditType }" >
				</td>
			</tr>
			
			<tr>
				<td colspan="2" align="center">	
				<a class="easyui-linkbutton" id="bt1" iconCls="icon-ok" onclick="save();">提交</a>  
	    		<a class="easyui-linkbutton" id="bt2" iconCls="icon-cancel" onclick="cancel();">取消</a>
				</td>
			</tr>
			</table>
		</form>
</body>
</html>
